﻿
using MediatR;
using Warehouse.API.Applcation.Command.WarehouseCommand;
using Warehouse.Infrstructre.Interface;

namespace Warehouse.API.Applcation.CommandHandlers.WarehouseCommandHndlers
{
    public class BatchDelWarehouseCommandHandlers : IRequestHandler<BatchDelWarehouseCommand, int>
    {
        private readonly IWarehouseRepository _warehouse;

        public BatchDelWarehouseCommandHandlers(IWarehouseRepository warehouse)
        {
            _warehouse = warehouse;
        }

        public async Task<int> Handle(BatchDelWarehouseCommand request, CancellationToken cancellationToken)
        {

            foreach (var item in request.ids)
            {
                var res = await _warehouse.GetModelAsync(item);
                res.IsDel = true;
                res.DelName = request.DelName;
                res.DelTime = DateTime.Now;
                await _warehouse.UpdateAsync(res);
            }

            return 1;
        }
    }
}
